package com.ningxun.pagent.bus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ningxun.pagent.bus.domain.BaseProtocol;
import com.ningxun.pagent.bus.service.IBaseProtocolService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ningxun.pagent.common.annotation.Log;
import com.ningxun.pagent.common.core.controller.BaseController;
import com.ningxun.pagent.common.core.domain.AjaxResult;
import com.ningxun.pagent.common.enums.BusinessType;

import com.ningxun.pagent.common.utils.poi.ExcelUtil;
import com.ningxun.pagent.common.core.page.TableDataInfo;

/**
 * 政策条款Controller
 *
 * @author pagent
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/system/protocol")
public class BaseProtocolController extends BaseController
{
    @Autowired
    private IBaseProtocolService baseProtocolService;

    /**
     * 查询政策条款列表
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseProtocol baseProtocol)
    {
        startPage();
        List<BaseProtocol> list = baseProtocolService.selectBaseProtocolList(baseProtocol);
        return getDataTable(list);
    }

    /**
     * 根据协议类型查询政策条款列表
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:list')")
    @GetMapping("/listByType/{protocolType}")
    public TableDataInfo listByProtocolType(@PathVariable("protocolType") String protocolType)
    {
        startPage();
        BaseProtocol baseProtocol = new BaseProtocol();
        baseProtocol.setProtocolType(protocolType);
        List<BaseProtocol> list = baseProtocolService.selectBaseProtocolList(baseProtocol);
        return getDataTable(list);
    }

    /**
     * 导出政策条款列表
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:export')")
    @Log(title = "政策条款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseProtocol baseProtocol)
    {
        List<BaseProtocol> list = baseProtocolService.selectBaseProtocolList(baseProtocol);
        ExcelUtil<BaseProtocol> util = new ExcelUtil<BaseProtocol>(BaseProtocol.class);
        util.exportExcel(response, list, "政策条款数据");
    }

    /**
     * 获取政策条款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:query')")
    @GetMapping(value = "/{protocolId}")
    public AjaxResult getInfo(@PathVariable("protocolId") Long protocolId)
    {
        return success(baseProtocolService.selectBaseProtocolByProtocolId(protocolId));
    }

    /**
     * 新增政策条款
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:add')")
    @Log(title = "政策条款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseProtocol baseProtocol)
    {
        return toAjax(baseProtocolService.insertBaseProtocol(baseProtocol));
    }

    /**
     * 修改政策条款
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:edit')")
    @Log(title = "政策条款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseProtocol baseProtocol)
    {
        return toAjax(baseProtocolService.updateBaseProtocol(baseProtocol));
    }

    /**
     * 删除政策条款
     */
    @PreAuthorize("@ss.hasPermi('system:protocol:remove')")
    @Log(title = "政策条款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{protocolIds}")
    public AjaxResult remove(@PathVariable Long[] protocolIds)
    {
        return toAjax(baseProtocolService.deleteBaseProtocolByProtocolIds(protocolIds));
    }
}
